package com.bajie.bjlisten.sevice;

import com.bajie.bjlisten.entity.BjChapters;
import com.bajie.bjlisten.mapper.BjChaptersMapper;
import com.bajie.bjlisten.utils.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * 章节
 */
@Service
public class BjChaptersService {
    @Autowired
    BjChaptersMapper bjChaptersMapper;

    /**
     * 分页查询获取小说最后更新的章节信息
      * @param offset
     * @param limit
     * @return
     */
    public Set<BjChapters> findByChapterTime(Integer offset,Integer limit){
        return bjChaptersMapper.findByChapterTime(offset, limit);
    }

    /**
     * 根据小说List的ebookId查询小说章节信息
     * 章节ID，简介、最新章节标题、最新章节的更新时间和总字数，排序，更新时间，总字数
     * @param ebookIds_list
     * @param offset
     * @param limit
     * @return
     */
    public Set<BjChapters> findChapterByEbookIds(Set<String> ebookIds_list, Integer offset, Integer limit){
        return bjChaptersMapper.findChapterByEbookIds(ebookIds_list, offset, limit);
    }

    /**
     * 根据小说id查询对应章节名
     * @param eBookId
     * @return
     */
    public List<BjChapters> selectChapterNameByEBookId(String eBookId){
        if (StringUtils.isNotEmpty(eBookId)){
            return bjChaptersMapper.selectChapterNameByEBookId(eBookId);
        }
        return  null;
    }

    /**
     * 根据小说ID分页查询小说的章节信息
     * @param ebookId
     * @param offset
     * @param limit
     * @return
     */
   public List<BjChapters> findChapterByEbookId(String ebookId, Integer offset,Integer limit){
        return bjChaptersMapper.findChapterByEbookId(ebookId, offset, limit);
   }

    /**
     * 根据章节id查询对应章节内容
     * @param chapterId
     * @return
     */
    public List<BjChapters> selectContentByChapterId(String chapterId){
        return bjChaptersMapper.selectContentByChapterId(chapterId);
    }

    /**
     * 根据小说id查询对应的章节名与章节id
     * @param eBookId
     * @return
     */
    public List<BjChapters> selectChapterIdAndChapterNameByEBookId(String eBookId){
        return  bjChaptersMapper.selectChapterIdAndChapterNameByEBookId(eBookId);
    }


}
